<template>
    <div class="weather-box">
        <img :src="dataSource.iconUrl" alt="">
        <div>
            <div>
                <span class="time">{{ currentTime }}</span>
                <span class="date">{{ currentDate }}</span>
            </div>
            <div class="info">
                <span class="weather">{{ dataSource.weather || '晴'}}</span>
                <img src="@/assets/images/BI/temperature.png" alt="">
                <span class="temperature">{{ dataSource.degree || '30'}}℃</span>
                <img src="@/assets/images/BI/humidity.png" alt="">
                <span class="humidity">{{ dataSource.humidity || '30'}} %</span>
                <!-- <img src="@/assets/images/BI/wind.png" alt=""> -->
                <!-- <span class="wind">{{ dataSource.windDirection || '东南' }} 30km/h</span> -->
            </div>
        </div>
    </div>
</template>
<script>
import moment from 'moment'
export default {
  name: 'weather',
  props:{
    dataSource:{
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
        timer:null,
        currentTime: '',
        currentDate:''
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
        this.timer = setInterval(() => {
            this.currentTime = this.$moment().format("HH:mm:ss");
            this.currentDate = this.$moment().format("YYYY-MM-DD");
            // this.currentDate = new Date().toLocaleDateString("zh-CN", {
            //     year: "numeric",
            //     month: "long",
            //     day: "numeric",
            // });
        }, 1000);
    }
  },
  beforeDestroy() {
    // 清除定时器，防止内存泄露
    clearInterval(this.timer);
  }
}
</script>
<style lang="scss" scoped>
.weather-box {
    display: flex;
    align-items: center;
    &>img{
        width: 8.7vh;
        margin-right: 0.5vw;
    }
    .time{
        font-size: 3.7vh;
        color: #333;
        font-weight: bold;
        position: relative;
        padding-right: 1.5vw;
        &::after{
            content: '';
            position: absolute;
            bottom: 5px;
            right: 0.5vw;
            width: 1px;
            height: 1.5vw;
            background: #888;
        }
    }
    .date{
        font-size: 1.5vh;
        color: #333;
    }
    .info{
        font-size: 1.73vh;
        padding-left: 5px;
        &> img{
            margin-left: 0.7vw;
            margin-right: 0.2vw;
        }
        &>span{
            vertical-align: text-top;
        }
    }
}
</style>